package com.torry.workflow.service.web.controller;


import com.torry.workflow.api.user.api.MenuApi;
import com.torry.workflow.api.user.entity.Menu;
import com.torry.workflow.common.base.result.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @DubboReference
    private MenuApi menuApi;

    @GetMapping("allMenus")
    public Result getAllMenus(){
        List<Menu> menus = menuApi.getAllMenus();
        return Result.selectSuccess(menus);
    }


    @PostMapping("saveMenuInfo")
    public Result saveMenuInfo(@RequestBody Menu menu) {
        menuApi.saveMenuInfo(menu);
        return Result.saveSuccess();
    }

    @DeleteMapping("deleteMenu/{ids}")
    public Result saveMenuInfo(@PathVariable String ids) {
        String[] idArr = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String s : idArr) {
            idList.add(Integer.parseInt(s));
        }

        menuApi.deleteByIds(idList);
        return Result.delSuccess();
    }

}
